package cn.cs.controller;
import cn.cs.common.Dto;
import cn.cs.common.DtoUtil;
import cn.cs.common.Page;
import cn.cs.es.common.EsUtils;
import cn.cs.es.document.AbatractESDocumentSetting;
import cn.cs.es.query.ItemQuery;
import cn.cs.item.ItemSearchVo;
import cn.cs.item.ItemSearchVoSetting;
import cn.cs.service.ItemSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/api/p/list")
public class ItemListController {

    @Autowired
    private ItemSearchService itemSearchService;
    @Resource
    private EsUtils esUtils;
    @RequestMapping("/queryItemList")
    public Dto<Page<ItemSearchVo>> queryItemList(@RequestBody ItemQuery itemQuery) throws Exception {
       Page<ItemSearchVo> searchVoList=itemSearchService.queryItemList(itemQuery);
       return DtoUtil.returnDataSuccess(searchVoList);
    }
    /**
     * 导入数据
     * */
    @RequestMapping("/importItemList")
    public Dto<Page<ItemSearchVo>> importItemList() throws Exception {
        itemSearchService.importItemList();
        return DtoUtil.returnDataSuccess(1);
    }
    /**
     * 创建索引
     * */
    @RequestMapping("/createIndex")
    public Dto createIndex(){
        AbatractESDocumentSetting itemSettings = new ItemSearchVoSetting();
        esUtils.initIndex(itemSettings);
        return DtoUtil.returnSuccess("创建成功");
    }

}
